package repository

import (
	"Data-API-MCP/backend/internal/domain/entity"
	"context"
)

// DBRepository 数据库仓储接口
type DBRepository interface {
	// 连接管理
	CreateConnection(ctx context.Context, conn *entity.DBConnection) error
	GetConnections(ctx context.Context, page, pageSize int, keyword string) ([]*entity.DBConnection, int64, error)
	GetConnection(ctx context.Context, id int64) (*entity.DBConnection, error)
	UpdateConnection(ctx context.Context, conn *entity.DBConnection) error
	DeleteConnection(ctx context.Context, id int64) error
	TestConnection(ctx context.Context, conn *entity.DBConnection) error

	// 表管理
	GetTables(ctx context.Context, id int64) ([]*entity.TableInfo, error)
	GetTableInfo(ctx context.Context, id int64, tableName string) (*entity.TableInfo, error)
	GetColumns(ctx context.Context, id int64, tableName string) ([]*entity.ColumnInfo, error)
	GetTableData(ctx context.Context, id int64, tableName string, page, pageSize int) (*entity.QueryResult, error)

	// 查询执行
	ExecuteQuery(ctx context.Context, id int64, query string) (*entity.QueryResult, error)
	ExecuteTransaction(ctx context.Context, id int64, queries []string) error
	ExecuteBatch(ctx context.Context, id int64, query string, params [][]interface{}) error

	// 数据库管理
	CreateDatabase(ctx context.Context, id int64, name string) error
	DropDatabase(ctx context.Context, id int64, name string) error
	CreateTable(ctx context.Context, id int64, tableName string, columns []*entity.ColumnInfo) error
	DropTable(ctx context.Context, id int64, tableName string) error
	AlterTable(ctx context.Context, id int64, tableName string, changes []string) error

	// 监控统计
	GetDatabaseStats(ctx context.Context, id int64) (*entity.DatabaseStats, error)
	GetTableStats(ctx context.Context, id int64, tableName string) (*entity.TableStats, error)
	GetQueryStats(ctx context.Context, id int64) ([]*entity.QueryStats, error)
	GetConnectionStats(ctx context.Context, id int64) (*entity.ConnectionStats, error)
	RecordQuery(ctx context.Context, id int64, stats *entity.QueryStats) error
	RecordConnection(ctx context.Context, id int64, stats *entity.ConnectionStats) error
}
